package org.itboys.core.controller.web;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.core.entity.mongo.SundayWeatherRecord;
import org.itboys.core.service.mongo.web.SundayWeatherRecordService;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Auther: 罗尧坤
 * Date: 2018/8/21
 * Description:
 */

@Controller
@RequestMapping("/sunday/web/weather")
public class SundayWeatherRecordController extends BaseController {

    @Autowired
    private SundayWeatherRecordService weatherRecordService;

    @RequestMapping("/index")
    public String index(
            HttpServletRequest request,
            HttpServletResponse response
    ){
        return "/sunday/weather/index";
    }

    /**
     * 分页查询天气记录
     * @param request
     * @param response
     */
    @RequestMapping("/select")
    public void select(HttpServletRequest request
            , HttpServletResponse response){
        try {
            PageResult<SundayWeatherRecord> result = weatherRecordService.select(request);
            JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),response);
        } catch (Exception e) {
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }
    }

}
